<include file="Public/head" />
<include file="Public/common_header" />
<div class="mian">
    <include file="Public/sidebar" menu="spgl.sp"  />
    <div class="mianR">
        <div class="shangPic"><img src="{:get_style_cdnurl()}paimai/yunying/images/yun_pic1.jpg"/></div>
        <div class="yuyue">
            <ul>
                <li onclick="change_search(0);get_list(4);" class="yuCurrent">待上拍</li>
                <li onclick="change_search(1);get_list(2);">审核驳回</li>
                <li onclick="change_search(2);get_list(5);">上拍成功</li>
                <li onclick="change_search(3);get_list(0);">上拍失败</li>
                <!--(4 待上拍,3 审核驳回,5 上拍成功, 0 上拍失败)-->
            </ul>
            <input type="hidden" name="car_status" value="4" />
        </div>
        <div class="shangFrom shangFrom1 clearfix">
            <div class="chang-ci">
                <input type="button" value="通用设置" id="feiyong"/>
                <input type="button" value="场次管理" id="xinjian1_1"/>
            </div>
            <input id="car_status" name="car_status" type="hidden" value="{$params.status}"/>
            <div class="zhuang-tai" id="search1">
                <input name="auction_status" type="text" data="" value="选择上拍类型" readonly />
                <dl>
                    <!--<dd data="3">全部</dd>-->
                    <dd data="4">待上拍</dd>
                    <dd data="7">待重拍</dd>
                </dl>
            </div>
            <div class="zhuang-tai">
                <select id="location_area" name="location_area" class="branch_company">
                    <if condition="count($bc_city) gt 1">
                        <option value="">请选择所在地</option>
                    </if>
                    <volist name="bc_city" id="city">
                        <option value="{$key}">{$city}</option>
                    </volist>
                </select>
            </div>
            <div class="deng-ji"><input type="text" name="keyword" value="车辆编号、等级"  onfocus="if (this.value == '车辆编号、等级' || this.value == '拍单编号') {
                        this.value = ''
                    }" onblur="set_prompt_info(this);"/></div><!--onfocus="if (this.value == '车辆编号、等级' || this.value == '拍卖单号') {
                        this.value = ''
                    }"  onblur="if (this.value == '') {
                                
                                this.value = '车辆编号、等级'
                            }"-->
            <div class="shangSou"><input type="button" id="searchBtn"  value="搜索"/></div>
        </div>

        <div class="listBox" id="listBox">
        </div>
        <!--上拍弹出窗口-->
        <style>
        .tanShang ul li .newtimes{width:100px;height:28px; line-height:28px; text-align:center;border-radius:5px; background:#20ab4f;color:#fff;font-size:14px;border:none;float:left;margin-left:10px; position:absolute;right:-55px;top:0;}
        .tanShang ul .statTime{ display:none;}
        .tanShang ul li .C_money{ position: absolute;top:27px;left:100px; background:#f0efef; z-index:999 ; display:none;}
        </style>

        <div class="yunBei"></div>
        <div class="tanShang" style="width:600px">
            <h3>上拍</h3>
            <ul style="padding-left:10px;" class="changList">
                <input type="hidden" name="scene_id" value="" />
                <li class="clearfix"><span>上拍场次</span>
                    <select class="city-select">
                        <if condition="count($bc_city) gt 1">
                            <option>选择城市</option>
                        </if>
                        <volist name="bc_city" id="city">
                            <if condition="$city_code eq $key">
                                <option value="{$key}" selected>{$city}</option>
                                <else/>
                                <option value="{$key}">{$city}</option>
                            </if>
                        </volist>
                    </select>
                    <select class="screenings">
                        <option value="">请选择上拍场次</option>
                    </select>
                </li>
                <li class="clearfix"><span>竞拍时长</span>
                    <input type="text" name="est_elapsed_time" class="qipai" value="{$est_elapsed_time}" onfocus="if (this.value == '请输入分钟数') { this.value = ''}" onblur="if (this.value == '') { this.value = '请输入分钟数'}"/><i class="yuan">分钟</i>
                </li>
                <li class="clearfix"><span>拍卖方式</span><input type="text" class="mianEr1" value="定时拍" readonly />
                <ul class="changList2">
                    <li>顺序拍</li>
                    <li>定时拍</li>
                </ul>
                </li>
                <li class="clearfix statTime"><span>竞拍开始时间</span><input type="text" id="demoText9" name="bidding_start_time" value="" placeholder="请选择开始时间" readonly /></li>

                <li class="clearfix">
                    <span>起拍价</span>
                    <input type="text" class="qipai money" name="bid_start_price" value="" placeholder="请输入起拍价" />
                    <input type="text" value="" class="C_money" />
                    <i class="yuan">元</i>
                </li>
                <li class="clearfix"><span>代金券</span><input type="text" value="" name="coupon" placeholder="请输入代金券可用金额" /></li>
                <li class="clearfix">
                    <span>交付服务费</span>
                    <input type="text" name="transfer_fee" value="{$transfer_fee}" class="money" />
                    <input type="text" value="" class="C_money" />
                    <i class="yuan">元</i>
                </li>
                <!--<li class="clearfix">-->
                    <!--<span>交易服务费</span>-->
                    <!--<input type="text" name="commision" value="{$commision}" class="money"/>-->
                    <!--<input type="text" value="" class="C_money" />-->
                    <!--<i class="yuan">元</i>-->
                <!--</li>-->
                <li class="clearfix">
                    <span>保留价</span>
                    <font id="reserve_price" class="baoliu" data="" style="float:left;"></font>
                    <div>
                        <input type="checkbox" value="1" name="show_reserve_price" id="show_reserve_price" style="width:15px;display:inner-block;float:left;margin-left:50px;border:0px solid #d2d2d2;"/>
                        <span style="width:30px;line-height:24px;">显示</span>
                    </div>
                </li>
                <li class="clearfix" style="display: none">
                    <span>建议价</span>
                    <font id="suggest_min_price" class="baoliu" data=""></font> - <font id="suggest_max_price" class="baoliu" data=""></font>
                </li>
                <li class="clearfix">
                    <input type="hidden" name="suggest_min_price" value="" />
                    <input type="hidden" name="suggest_max_price" value="" />    
                    <input type="hidden" name="car_id" value=""/>
                    <input type="button" value="确定" class="queding"/>
                    <input type="button" value="取消" class="quxiao"/>
                </li>
            </ul>
        </div>
        <!--上拍弹出窗口结束-->

        <!--通用设置开始-->
        <div class="tanShang1">
            <h3>通用设置</h3>
            <ul>
                <li class="clearfix"><span>分公司</span>
                    <select id="branch_id" name="branch_id" class="branch_company">
                        <if condition="count($branch_company) gt 1">
                            <option value="">请选择分公司</option>
                        </if>
                        <volist name="branch_company" id="branch">
                            <option value="{$key}">{$branch}</option>
                        </volist>
                    </select>
                </li>
                <li class="clearfix"><span>交付服务费</span><input type="text" id="transfer_fee" value="{$transfer_fee}"/><i class="yuan">元</i></li>
                <!--<li class="clearfix"><span>交易佣金</span><input type="text" id="commision" value="{$commision}"/><i class="yuan">元</i></li>-->
                <li class="clearfix"><span>竟拍时长</span><input type="text" id="est_elapsed_time" value="{$est_elapsed_time}"/><i class="yuan">分</i></li>
                <li class="clearfix"><input type="button" value="确定" class="queding" id="fee_confirm"/><input type="button" value="取消" class="quxiao"/>
                </li>
            </ul>
        </div>
        <!--通用设置结束-->

        <!--新建场次-->
        <div class="tanShang2 tanShang6">
            <h3>新建场次</h3>
            <ul>
                <li class="clearfix"><span>场次名称</span><input type="text" name="name" value=""/></li>
                <li class="clearfix"><span>开场时间</span><input type="text" name="starttime" class="shijian" value="" id="demoText10"/></li>
                <li class="clearfix"><input type="button" value="确定" class="queding" id="scene_submit"/><input type="button" value="取消" class="quxiao"/>
            </ul>
        </div>
        <!--新建场次结束-->
        <!--您已上拍成功-->
        <div class="chenggong">
            <div class="yunGou"></div>
            <span>上拍成功！</span>
            <p>等待审核中...</p>
        </div>
        <!--您已上拍成功结束-->
        <div class="clear"></div>
    </div>
</div>
<script>
    $(document).ready(function() {
        getScene();
        $(".city-select").change(function(){
            getScene();
        });

        $(".tanShang ul li .newtimes").click(function(){
               $(".tanShang").fadeOut();
               $(".tanShang2").fadeIn();
           })
        $(".tanShang ul li .mianEr1").click(function(event){
            $(".tanShang ul li .changList2").fadeToggle();
            event.stopPropagation();
        })

        $(".tanShang ul li .changList2 li").click(function(event){
            $(".tanShang ul li .mianEr1").val($(this).html());
            $(".tanShang ul li .changList2").fadeOut();
            if($(this).html()=="定时拍"){
                $(".tanShang ul .statTime").css("display","block");
            }else{
                $(".tanShang ul .statTime").css("display","none");
                $('input[name=bidding_start_time]').val('')
            }
            event.stopPropagation();
        });
        $(".tanShang ul .statTime").css("display","block");
        $("body").click(function(event){
            $(".tanShang ul li .changList2").fadeOut();
            $(".C_money").fadeOut();
            event.stopPropagation();
        })
    });

    //根据城市code 获取场次
    function getScene() {
        var city_code = $(".city-select option:selected").val();
        $.ajax({
            type:"post",
            url:'/AuOrder/get_scenes_by_city',
            data:{"city":city_code},
            dataType:"json",
            success:function(res){
                $('input[name=scene_id]').val('');
                $(".screenings").html("<option value=''>请选择上拍场次</option>");
                if(res.data){
                    $.each(res.data,function (i,item) {
                        $(".screenings").append("<option value='"+item.scene_id+"'>"+item.name+"</option>");

                        //console.log(res)
                    })
                }
            }
        });
    }
</script>
<script type="text/javascript">

    get_list(4);
    function get_list(status) {
        if(status == 2 || status == 5){
            $('input[name=keyword]').val('拍单编号');
        }else{
            $('input[name=keyword]').val('车辆编号、等级');
        }

        $('#car_status').val(status);
        var url = mkurl();
        //$('input[name=car_status]').val(status);
        var param = {};
        $.get(url, param, function (data) {
            $("#listBox").html(data);
        }, "html");
    }
    
    function set_prompt_info(obj) {
        var status = $('#car_status').val();
        if(obj.value == ''){
            if(status == 2 || status == 5){
                obj.value = '拍单编号';
            }else{
                obj.value = '车辆编号、等级';
            }
        }

    }

    //页签切换，显示不同的搜索条件
    function change_search(st) {
        var s1 = $("#search1");
        //clear_params();
        if (st == 1 || st == 2 || st == 3) {
            s1.hide();
        }else{
            s1.show();
        }
    }

    function clear_params() {
        $("#order_id").val("");
        $("#demoText2").val("");
    }


    //ajax 获取分页内容
    function get_page(p) {
        var data = "car_status=" + $('input[name=car_status]').attr('data') + "&" + encodeURI("p=" + p);
        var url = mkurl();
            data = {
                "p":p
            };
        $.get(url, data, function (data) {
            $("#listBox").html(data);
        }, "html");
    }
    //搜索
    $("#searchBtn").on('click', function () {
        var url = mkurl();
        var param = {};
        $.get(url, param, function (data) {
            $("#listBox").html(data);
        }, "html");
    });
   
    function mkurl(){
        var url = '/Car/get_list';
        var car_status = $('#car_status').val();
        //alert(car_status);
        if(car_status == 4){
            var auction_status =  $('input[name=auction_status]').attr('data');
            if(auction_status){
                url += '/car_status/' + auction_status;
            }else{
                url += '/car_status/' + 'all';
            }
        }else{
            if (car_status) {
                url += '/car_status/' + car_status;
            }
        }

        var location_area = $('select[name=location_area]').val();
        if (location_area) {
            url += '/location_area/' + location_area;
        }
        var keyword = $('input[name=keyword]').val();
        if (keyword && keyword != '车辆编号、等级' && keyword != '拍单编号') {
            url += '/keyword/' + encodeURIComponent(keyword);
        }
        return url;
    }
    //上拍表单弹窗
    function onsale(car_id) {

        $(".yunBei").fadeIn();
        $(".tanShang").fadeIn();
        $("input[name=car_id]").val(car_id);
        //获取保留价,建议最低价，建议最高价,起拍价
        $.get("/Car/get_reserve_price/car_id/" + car_id, function (data) {
            if (data.code == '200') {
                $("#reserve_price > font").attr(data.data.reserve_price);
                $("#reserve_price").html(data.data.reserve_price_cn + '元');
                $("#suggest_min_price").html(data.data.suggest_min_price_cn + '元');
                $("#suggest_max_price").html(data.data.suggest_max_price_cn + '元');
                $('input[name=suggest_min_price]').val(data.data.suggest_min_price);
                $('input[name=suggest_max_price]').val(data.data.suggest_max_price);

                if(data.data.car_status == 7){
                    $('input[name=bid_start_price]').val(data.data.last_order_best_price);
//                    $('input[name=bid_start_price]').attr("readonly","readonly");
                }else{
                    $('input[name=bid_start_price]').val(data.data.suggest_bid_start_price);
//                    $('input[name=bid_start_price]').removeAttr("readonly");
                }
            } else {
                $("#reserve_price").html('0元');
                $("#suggest_min_price").html('0元');
                $("#suggest_max_price").html('0元');
            }
        }, 'json');

    }
    //上拍提交
    $(".tanShang ul li .queding").on('click', function () {
        var car_id = $('input[name=car_id]').val();
        var scene_id = $('input[name=scene_id]').val();

        var show_reserve_price = $("input[name='show_reserve_price']:checked").val();
        if(show_reserve_price){
             is_show_reserve_price = show_reserve_price;
        }else{
            is_show_reserve_price = 0;
        }
        if ($.trim(scene_id) == '') {
            shibai_alert('请选择场次');
            return;
        }
        var est_elapsed_time = $('input[name=est_elapsed_time]').val();
        if (parseInt(est_elapsed_time) <= 0) {
            shibai_alert('竞拍时长要大于0');
            return;
        }
        //竞拍方式
        var bidding_start_time = $('input[name=bidding_start_time]').val();
        var au_method = $(".tanShang ul li .mianEr1").val();
        if(au_method=='定时拍'){
            if(bidding_start_time==''){
                shibai_alert('请指定竞拍开始时间');
                return;
            }
        }

        var bid_start_price = $('input[name=bid_start_price]').get(0).value;
        if (bid_start_price != '请输入起拍价') {
            if (bid_start_price <= 0) {
                shibai_alert('起拍价要大于0');
                return;
            } else {
                var reserve_price = parseFloat($('.baoliu').attr('data'));
                if (bid_start_price > reserve_price) {
                    shibai_alert('提示：起拍价应该小于保留价。');
                    return;
                }
            }
        } else {
            shibai_alert('起拍价不能为空')
            return;
        }
        var coupon = $('input[name=coupon]').val();
        var commision = $('input[name=commision]').val();
        if ($.trim(commision) == '') {
            //shibai_alert('佣金不能为空')
            //return;
        }
        var transfer_fee = $('input[name=transfer_fee]').val();
        if ($.trim(transfer_fee) == '') {
            shibai_alert('交付服务费不能为空')
            return;
        }
        var est_elapsed_time = $('input[name=est_elapsed_time]').val();

        var suggest_min_price = $('input[name=suggest_min_price]').val();
        var suggest_max_price = $('input[name=suggest_max_price]').val();
        var param = {
            'car_id': car_id,
            'scene_id': scene_id,
            'est_elapsed_time': est_elapsed_time,
            'bidding_start_time': bidding_start_time,
            'bid_start_price': bid_start_price,
            'coupon': coupon,
            'transfer_fee': transfer_fee,
//            'commision': commision,
            'show_reserve_price':is_show_reserve_price,
            'suggest_max_price':suggest_max_price,
            'suggest_min_price':suggest_min_price
        };
        var btn_obj = $(this);
        btn_obj.val("提交中...").attr("disabled",'disabled');
        $.post('/Car/add_order', param, function (data) {
            if (data.code == '200') {
                $(".yunBei").css("display", "none");
                $(".tanShang").fadeOut();
                btn_alert(data.msg);
                var status = $('#car_status').val();
                get_list(status);
                btn_obj.val("确定").removeAttr("disabled style");
            } else {
                shibai_alert(data.msg);
                btn_obj.val("确定").removeAttr("disabled style");
                return false;
            }
        }, "json");

    });

    //通用设置
    $("#fee_confirm").on('click', function () {
        var branch_id = $('#branch_id').val();

        if ($.trim(branch_id) == '') {
            shibai_alert('分公司不能为空')
            return;
        }

        var commision = $('#commision').val();
        var transfer_fee = $('#transfer_fee').val();
        var est_elapsed_time = $('#est_elapsed_time').val();
        $.post('/Car/set_fee', {'branch_id': branch_id,'commision': commision, 'transfer_fee': transfer_fee, 'est_elapsed_time': est_elapsed_time}, function (data) {
            btn_alert(data.msg);
            if (data.code == '200') {
                $(".yunBei").css("display", "none");
                $(".tanShang1").fadeOut();
            }

        }, "json");
    });

    //状态赋值
    $(".zhuang-tai dl dd").click(function () {
        $('input[name=auction_status]').attr('data', ($(this).attr('data')));
    });
    //选择场次后把值赋于 name  为 scene的控件

    $(".screenings").change(function () {

            $("input[name=scene_id]").val($(".screenings option:selected").val());

        console.log($(".screenings option:selected").val())
    })

    //选择代金券后把值赋于 name  为 coupon的控件
    $(".changList1 li").on('click', function () {
        $("input[name=coupon]").val($(this).attr('data'));
    })
    //取消按钮事件监听
    $(".quxiao").on('click', function () {
        $(".yunBei").css("display", "none");
        $(".tanShang").fadeOut();
        $(".tanShang1").fadeOut();
        $(".tanShang2").fadeOut();
    });
    //场次管理
    $('#xinjian1_1').on('click', function () {
        window.location.href = '/AuOrder/scene';
    })
    //新建场次
    $('#scene_submit').click(function(){

    })
    //报告失效
    function failureReport(car_id) {
        confirm_alert('<div style="color:red">确定报告失效了吗？</div>', function () {
            $(".determine").click(function () {
                $.post('/Car/failureReport',{car_id:car_id},function (data) {
                    if(data.code != 200){
                        shibai_alert(data.msg, 500, function(){
                            colse_hide();
                        });
                        return ;
                    }
                    colse_hide();
                    btn_alert("操作成功", 500, function () {
                        window.location.reload();
                    });
                },'json');
            })
        });
    }
</script>
<include file="Public/foot" />